package utils.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.myapplication.R;
import com.lanou.horo.myapplication.dbdao.HistoryEntity;
import com.lanou.horo.myapplication.dbdao.RecommendDbEntity;

import java.util.List;

import volley.VolleySingleton;

/**
 * Created by dllo on 15/11/30.
 */

public class HistoryDbAdpter extends BaseAdapter {
    private List<HistoryEntity> entityList;
    LayoutInflater inflater;
    public  void  addData(LayoutInflater inflater,List<HistoryEntity> entityList){
        this.entityList = entityList;
        this. inflater = inflater;
        notifyDataSetChanged();

    }

    @Override
    public int getCount() {
        return entityList != null && entityList.size() > 0? entityList.size() :0;
    }

    @Override
    public Object getItem(int position) {
        return entityList.size();
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (entityList != null && entityList.size() >0){
            ViewHolder holder = null;
            if (convertView == null){
                holder = new ViewHolder();
                LayoutInflater inflater = LayoutInflater.from(parent.getContext());
                convertView  =inflater.inflate(R.layout.collection_item,null);
                //初始化控件
                holder.collectionContent= (TextView) convertView .
                        findViewById(R.id.collectionItemImgItemTopContent);
                holder.collectionItemImgItemTopTitle = (TextView) convertView.
                        findViewById(R.id.collectionItemImgItemTopTitle);
                holder.collectionItemImg = (NetworkImageView) convertView.
                        findViewById(R.id.collectionItemImg);
                holder.times = (TextView) convertView.findViewById(R.id.times);

                convertView.setTag(holder);
            }
            else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.times.setText(entityList.get(position).getTimes());
            holder.collectionContent.setText(entityList.get(position).getNickname());
            VolleySingleton.getInstance().getBitmap(entityList.get(position).getSmallLogo(),
                    holder.collectionItemImg);
            holder.collectionItemImgItemTopTitle.setText(entityList.get(position).getTitle());
        }
        return convertView;
    }

    class  ViewHolder {
        private TextView collectionContent,collectionItemImgItemTopTitle,times;
        private NetworkImageView collectionItemImg;

    }
}
